package apache.openejb.session.bean.stateless.client;

import java.net.InetAddress;
import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;

import apache.openejb.session.bean.stateless.HelloWorldRemote;

public class HelloWorldRemoteClient{
    
    public static void main(String[] args) throws Exception{
        Properties props = new Properties();
        props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.RemoteInitialContextFactory");
        //different vm in different machine
        props.put(Context.PROVIDER_URL, "http://192.168.1.252:8080/tomee/ejb");
        //different vm in same machine
        //props.put(Context.PROVIDER_URL, "http://localhost:8080/tomee/ejb");

        Context ctx = new InitialContext(props);
        Object ref = ctx.lookup("HelloWorldImplRemote");
        HelloWorldRemote r = (HelloWorldRemote)PortableRemoteObject.narrow(ref, HelloWorldRemote.class);

        String hostname = InetAddress.getLocalHost().getHostName();

        String result = r.sayHello("Hello World by remote client at " + hostname);
        System.out.println(result); 
    }
}